package com.example.yang.yixin.Adapter;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.yang.yixin.Activity.BankeActivity;
import com.example.yang.yixin.R;
import com.example.yang.yixin.Utils.Person_info;

import org.w3c.dom.Text;

import java.util.List;

public class PersonAdapter extends RecyclerView.Adapter<PersonAdapter.ViewHolder> {
    private List<Person_info> person_infoList;



    public PersonAdapter(List<Person_info> person_infoList) {
        this.person_infoList = person_infoList;

    }

    @NonNull
    @Override
    public PersonAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        View view=LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.person_info,viewGroup,false);
        final PersonAdapter.ViewHolder holder=new PersonAdapter.ViewHolder(view);
        holder.Person_info.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                int position=holder.getAdapterPosition();
                Person_info person_info=person_infoList.get(position);
                /*
                具体的跳转
                 */

                String username=person_info.getusername();
                String name=person_info.getname();
                String classname=person_info.getclassname();
                Intent intent=new Intent();
                intent.putExtra("username",username);
                intent.putExtra("name",name);
                intent.putExtra("classname",classname);
                intent.setClass(v.getContext(),BankeActivity.class);


            }
        });

        return holder;
    }




    public void onBindViewHolder(PersonAdapter.ViewHolder viewHolder, final int position) {
      Person_info personInfo=person_infoList.get(position);
        viewHolder.rootname.setText(personInfo.getusername());
        viewHolder.coursename.setText(personInfo.getname());
        viewHolder.cname.setText(personInfo.getclassname());
        viewHolder.itemView.setTag(position);



    }


    @Override
    public int getItemCount() {
        return person_infoList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView rootname;
        TextView coursename;
        TextView cname;
        View Person_info;

        public ViewHolder(View view){
            super(view);
            Person_info=view;
            rootname=(TextView) view.findViewById(R.id.username);
            coursename=(TextView) view.findViewById(R.id.name);
            cname=(TextView)view.findViewById(R.id.banji);

        }



    }
}
